package view;

import java.awt.BorderLayout;
import java.awt.Container;
import java.io.File;
import javax.swing.JFrame;
import javax.swing.JPanel;
import ressources.Constant;
import controler.Game;
import modelImp.Board;

public class MainWindow extends JFrame {
	private static final long serialVersionUID = -2919223489269635560L;
	
	JPanel mainPanel = new JPanel(new BorderLayout());
	public PiocheButton piocheButton;
	public BoardPanel boardPanel;
	public GamePanel gamePanel;
	public GameMenu menuWindow;
	private JPanel north;
	public MessagesPanel messages;
	private ActifPlayersPanel actifPlayersPanel = new ActifPlayersPanel();
	public MainWindow()
	{
		super("Carcassonne Game");
		this.gamePanel= new GamePanel();
		this.setSize(800, 650);
		this.setVisible(true);
		this.boardPanel = new BoardPanel();
		this.gamePanel = new GamePanel();
		menuWindow = new GameMenu(this);	
		this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		this.initPanel();
	}
	
	
	public void replaceActifPlayersPanel(ActifPlayersPanel panel){
		for(int i=0;i<this.north.getComponentCount();i++){
			if(this.north.getComponent(i) instanceof ActifPlayersPanel){
				this.north.remove(i);
			}
		}
		this.north.add(panel);
		this.validate();

		
	}
	
	private void initPanel() {
		Container c = this.getContentPane();
		c.add(mainPanel);
		mainPanel.add(boardPanel,BorderLayout.CENTER);
		mainPanel.add(gamePanel,BorderLayout.EAST);
		
		north = new JPanel();
		north.setLayout(new RowLayout());
		north.add(menuWindow);
		north.add(actifPlayersPanel);
		mainPanel.add(north,BorderLayout.NORTH);
		
		messages = new MessagesPanel();
		mainPanel.add(messages,BorderLayout.SOUTH);
		
	}
	
	
}
